<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<input type="text" name="cancel_reason" id="cancel_reason" placeholder="取消原因" class="layui-input">
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
			<button class="layui-btn layui-btn-normal" data-url="{:url('add')}" onclick="add_t(this,'添加取消原因')">
				添加取消原因
			</button>
		</div>
	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('CancelReason/index')}', page: true, limit: 10, id:'CancelReason'}" lay-filter="CancelReason">
		<thead>
		<tr>
			<th lay-data="{field:'id', width:70,fixed: true, sort: true,align:'center',fixed: true}">ID</th>
			<th lay-data="{field:'cancel_reason', width:300,align:'center'}">取消原因</th>
			<th lay-data="{field:'admin_name', width:120,align:'center'}">添加人</th>
			<th lay-data="{field:'add_time', width:160,align:'center'}">时间</th>
			<th lay-data="{field:'update_admin_name', width:120,align:'center'}">修改人</th>
			<th lay-data="{field:'update_time', width:160,align:'center'}">修改时间</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:210, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 50px">删除</a>
		{{#  if(d.award_type == 2){ }}
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="coupon" style="width: 50px">优惠券</a>
		{{#  } }}
	</script>
	<script>
		layui.use(['form','table'], function () {
			var table = layui.table,form = layui.form;
			table.on('tool(CancelReason)', function (obj) {
				var data = obj.data;
				var id = data.id;
				if (obj.event === 'edit') {
					layer.open({
						type: 2,
						title: '编辑信息',
						shadeClose: true,
						shade: 0.8,
						area: ['80%', '80%'],
						content: '{:url("/admin/CancelReason/edit","id=")}' + id //iframe的url
					});
				}else if (obj.event === 'del') {
					layer.confirm('确定删除吗?',function(index){
						var url = '{:url("/admin/CancelReason/del","id=")}' + id
						$.get(url,function(data){
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
								window.location.reload();
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						},'json')
						layer.close(index);
					})
				}
			});
			//搜索
			$('.layui-btn').on('click', function () {
				var cancel_reason 	= $("#cancel_reason").val();
				table.reload('CancelReason', {
					url: '/admin/CancelReason/index', where: {
						"cancel_reason": cancel_reason,
					}
				});
			});
		});
	</script>
</block>
